<?php
/*
+ --------------------------------------------------- +
|  Ineo Article Manager - Version 1.x
|  Copyright 2006-2007, Dan Cryer and William McGann
+ --------------------------------------------------- +

Ineo Article Manager is free software; you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License as published by
the Free Software Foundation.

Ineo Article Manager is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Ineo; see the file License.txt.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

*/

/**
* Ineo - Modules - Moderation
*  
* This module handles all front-end actions related to moderation.
*
* @package		Ineo
* @subpackage   Modules
* @author		Dan Cryer & William McGann
* @copyright	Dan Cryer & William McGann
* @version		1.0.0
*/
class ineo_mod_moderator
{
  var $ipsclass;
  var $core;
  
  /**
  * Load moderator libraries
  */
  function module_init()
  {
    $this->lib_global =& $this->core->load_library('global');
    $this->lib_mod =& $this->core->load_library('moderator');
    $this->core->load_template('mod');
  }
  
  /**
  * List articles with more than 1 revision, blah blah
  * @todo Review to ensure that all links/features are working, and check for api-needins
  */
	function revisions()
	{
    //----
    // Finding articles with more than 1 revision, and displaying them in a list
    //----
    
	  $start = ( empty($this->ipsclass->input['st']) ) ? '0' : $this->ipsclass->input['st'];
    
	  // Query:
    $this->ipsclass->DB->simple_construct( array( 'select' => 'article_id,article_title,article_edited_date,article_revisions',
                                                  'from'   => 'ams_articles',
                                                  'where' => 'article_revisions > \'1\'' ) );
    $this->ipsclass->DB->simple_order( 'article_edited_date DESC' );
    $this->ipsclass->DB->simple_limit( $start, $this->ipsclass->vars['ams_revision_count'] );
    $list = $this->ipsclass->DB->simple_exec();
    $this->core->nav_add( $this->ipsclass->lang['ams_rev_manager'] , 'mod=moderator&op=revisions' );
    $rows = '';
    
    //----
    // Counting to determine how many pages there will be
    //----
    
    $this->ipsclass->DB->simple_select( 'count(*) as cnt', 'ams_articles', 'article_revisions > \'1\'');
    $count = $this->ipsclass->DB->simple_exec();
    $count = $this->ipsclass->DB->fetch_row( $count );
    $count = $count['cnt'];
    
    // Build list using the template:
    while( $res = $this->ipsclass->DB->fetch_row( $list ) )
    {
  	  // Make the date from timestamp:
      $res['article_date'] = $this->ipsclass->get_date($res['article_edited_date'],'');

      $rows .= $this->core->templates['mod']->revision_manager_row( $res );
		}
		
		$links = $this->ipsclass->build_pagelinks( 
											   array( 
											   'TOTAL_POSS'  => $count,
											   'PER_PAGE'    => $this->ipsclass->vars['ams_revision_count'],
											   'CUR_ST_VAL'  => $start,
											   'BASE_URL'    => $this->core->base_url.'mod=moderator&op=revisions', ) );

		$this->core->out .= $this->core->templates['mod']->revision_manager( $rows, $links );
	}
	
	/**
	* @todo Check for api-needins
	*/
	function rev_list()
	{
    //----
    // This function will pull the revisions (active and inactive, and queued/unqueued) and display them for
    // the specified article. Eets smart.
    //----
    
	  $start = ( empty($this->ipsclass->input['st']) ) ? '0' : $this->ipsclass->input['st'];
	  
	  // Query:
	  if ( $this->ipsclass->member['g_ams_ismod'] == '0' && $this->ipsclass->vars['ams_revision_memberview'] == '0' )
	  {
	    // This will only pull unqueued articled, depending on the ACP setting and the member's permissions
	    $this->ipsclass->DB->simple_construct( array( 'select' => 'a.*,c.*,m.members_display_name',
	                                                  'from' => array( 'ams_articles' => 'a' ),
	                                                  'add_join' => array( 1 =>
	                                                                array( 'type' => 'left',
	                                                                       'from' => array( 'ams_content' => 'c' ),
	                                                                       'where' => 'c.content_article=a.article_id and c.content_is_queued = \'0\'' ),
	                                                                       2 =>
	                                                                array( 'type' => 'left',
	                                                                       'from' => array( 'members' => 'm' ),
	                                                                       'where' => 'c.content_author=m.id' ),
	                                                                     ),
	                                                  'where' => 'a.article_id = ' . $this->ipsclass->input['id']
	                                                )
	                                         );
	  }
	  else
	  {
	    // This will pull all articles, queued -and- unqueued.
	    $this->ipsclass->DB->simple_construct( array( 'select' => 'a.*,c.*,m.members_display_name',
	                                                  'from' => array( 'ams_articles' => 'a' ),
	                                                  'add_join' => array( 1 =>
	                                                                array( 'type' => 'left',
	                                                                       'from' => array( 'ams_content' => 'c' ),
	                                                                       'where' => 'c.content_article=a.article_id' ),
	                                                                       2 =>
	                                                                array( 'type' => 'left',
	                                                                       'from' => array( 'members' => 'm' ),
	                                                                       'where' => 'c.content_author=m.id' ),
	                                                                     ),
	                                                  'where' => 'a.article_id = ' . $this->ipsclass->input['id']
	                                                )
	                                         );
	  }
	  $this->ipsclass->DB->simple_order( 'c.content_date DESC' );
	  $this->ipsclass->DB->simple_limit( $start, 10 );
	  $content = $this->ipsclass->DB->simple_exec();
	  
    $rows = '';
    
    // Build list using the template:
    while( $res = $this->ipsclass->DB->fetch_row( $list ) )
    {
			if( !isset( $nav_added ) )
			{
			  // Adding navigation
			  $nav_added = 1;
			  $this->core->nav_add( $res['article_title'] , 'showarticle=' . $res['article_id'] );				
			  $this->core->nav_add( $this->ipsclass->lang['ams_article_revisions'] , 'mod=moderator&op=rev_list&id=' . $res['article_id'] );
			}
			
		if( $res['content_is_queued'] )
		{
			$res['class'] = 'row4shaded';
		}
		else
		{
			$res['class'] = 'row2';
		}
		
		// Make the date from timestamp:
    $res['content_date'] = $this->ipsclass->get_date($res['content_date'],'');
    
    // Set the name based on guest or nein.
    $res['members_display_name'] = ( !is_numeric( $res['content_author'] ) ) ? $res['content_author'] : $res['members_display_name'] ;
    $title = $res['article_title'];
    
    $res['article_is_active'] = ( $res['article_content'] == $res['content_id'] ) ? true : false;
    
	  if( $res['article_is_active'] )
	  {
		  $res['style_add'] = ' style="font-weight: bold;"';
	  }
	  else
	  {
		  $res['style_add'] = '';
	  }
	

      $rows .= $this->core->templates['mod']->revision_manager_artrow( $res );
		}
		
    //----
    // Counting for pagination links, depending on how many articles are actually being pulled.
    //----
    
	  if ( $this->ipsclass->member['g_ams_ismod'] == '0' && $this->ipsclass->vars['ams_revision_memberview'] == '0' )
	  {
	    $this->ipsclass->DB->simple_select( 'count(*) as cnt', 'ams_content', 'content_article = ' . $this->ipsclass->input['id'] . ' AND content_is_queued = \'0\''  );
	    $count = $this->ipsclass->DB->simple_exec();
	    $count = $this->ipsclass->DB->fetch_row( $count );
	  }
	  else
	  {
	    $this->ipsclass->DB->simple_select( 'count(*) as cnt', 'ams_content', 'content_article = ' . $this->ipsclass->input['id'] );
	    $count = $this->ipsclass->DB->simple_exec();
	    $count = $this->ipsclass->DB->fetch_row( $count );
	  }
		
		$links = $this->ipsclass->build_pagelinks( array( 'TOTAL_POSS' => $count['cnt'],
		                                                  'PER_PAGE' => 10,
		                                                  'CUR_ST_VAL' => $start,
		                                                  'BASE_URL'    => $this->core->base_url.'mod=moderator&op=rev_list&id='
		                                                  . $this->ipsclass->input['id'],) );
		                                                  
		$this->core->out .= $this->core->templates['mod']->revision_manager_article( $rows,$title,$links );
		
		if ( $this->ipsclass->member['g_ams_ismod'] == '1' || $this->ipsclass->vars['ams_revision_memberview'] == '1' )
	  {
	    $this->ipsclass->DB->do_update( 'ams_articles', array( 'article_revisions' => $count['cnt'] ), 'article_id = ' . $this->ipsclass->input['id'], true );
	  }
	}
	
  function art_view()
  {
    // Since we don't need article templates anywhere else, we load it here.
    $this->core->load_template('articles');
    // Ditto for articles library.
    $this->lib_art =& $this->core->load_library('articles');
    
    $article = $this->lib_art->load_article_data( $this->ipsclass->input['id'] );
    
    // If article doesn't exist, this prevents a nasty SQL error.
    if ( !$article )
    {
      $this->core->error( 'ams_artiview_noart' );
      return;
    }
    
	  $this->core->title .= ' - ' . $article['article_title'];
    $this->core->nav_add( $article['article_title'], 'showarticle=' . $article['article_id'] );
    
    // Creating dates from timestamps. ips_kernel > all
    $dates = array( 'created_date' => $this->ipsclass->get_date( $article['article_created_date'], '' ),
                    'edited_date' => $this->ipsclass->get_date( $article['article_edited_date'], '' ) );

    // Hand the article's content to the application for parsing
    $body = $this->core->api->display_parse( $article['content_content'] );
    
    // Determine what the article views value should be set to, then do eet on shutdown.
    $article['article_views'] = $article['article_views'] + 1;
    $this->ipsclass->DB->do_update( 'ams_articles', array( 'article_views' => $article['article_views'] ), 'article_id = ' . $this->ipsclass->input['id'], true );
    
    // Build resources box
    $this->ipsclass->DB->simple_construct( array( 'select' => '*',
	                                              'from' => 'ams_attachments',
	                                              'where' => 'attach_article = '.intval($this->ipsclass->input['id']) ) );
    $this->ipsclass->DB->simple_exec();
    $attachments = '';
    while( $data = $this->ipsclass->DB->fetch_row() )
    {
      $attachments .= '- <a href="'.$this->core->base_url.'downloadfile='.$data['attach_id'].'">
                      '.$data['attach_file'].'</a> <i>'.$this->ipsclass->size_format($data['attach_size']).'</i><br />';
    }
    if ( $article['article_links'] != '' )
    {
      $resource_links = '';
      $link_array = explode( "\n", str_replace( "<br />", "\n", $article['article_links']) );
      foreach ( $link_array as $link )
      {
        $ldata = explode( '||', $link);
        if ( !$ldata['1'] ) { $desc = ''; }
        else { $desc = ' <i>'.$ldata['1'].'</i>'; }
        $resource_links .= '- <a href="'.$ldata['0'].'">'.$ldata['0'].'</a> '.$desc.'<br />';
      }
    }
    $resources = $this->core->templates['articles']->art_resources($attachments,$resource_links);

    $this->core->out .= $this->core->templates['mod']->revision_manager_articleview($article,$dates,$body,$resources);
    
    //----
    // Menu Additions:
    //----
    
    // Create the block:
    $this->core->menu_block( 'ams_this_article' );
    
    // Set up the links:
    $opts = array( 
    	'ams_mq_artapp' => 'mod=moderator&op=mq_art_app&id='.$this->ipsclass->input['id'],
    	'ams_mq_artden' => 'mod=moderator&op=mq_art_den&id=' . $this->ipsclass->input['id'],
    			);
    
    // Add 'article options' section:
    $this->core->menu_block_section( 'ams_article_options' , $opts );
    
    // Set created by info:
    /**
    * @todo We needs to fix this... IPB-only linkage going on.
    */
    if ( $article['article_author'] == 0 )
    {
      $sec = "<b>" . $this->ipsclass->lang['ams_created_by'] . ":</b> <i>" . $article['members_display_name'] ."</i>
      <br /><b>{$this->ipsclass->lang['ams_on']}:</b> " . $dates['created_date'];
    }
    else
    {
      $sec = "<b>" . $this->ipsclass->lang['ams_created_by'] . ":</b> " .
    	    "<a href='{$this->ipsclass->base_url}showuser={$article['article_author']}'>" .
    		  $article['members_display_name'] .
    		  "</a>
    		  <br />
    		  <b>{$this->ipsclass->lang['ams_on']}:</b> " . $dates['created_date'];
    }
    
    // Set edited by info:
    if( !empty( $article['last_edited_by'] ) )
    {
      /**
      * @todo We needs to fix this... IPB-only linkage going on.
      */
      if ( $article['article_edited_by'] == 0 )
      {
   	 	  $sec .= "<br /><br /><b>" . $this->ipsclass->lang['ams_last_edited_by'] . ":</b> <i>" . $article['last_edited_by'] . "</i>" .
    	  "<br /><b>{$this->ipsclass->lang['ams_on']}:</b> {$dates['edited_date']}";
      }
      else
      {
   	 	  $sec .= "<br /><br /><b>" . $this->ipsclass->lang['ams_last_edited_by'] . ":</b> " .
    	  "<a href='{$this->ipsclass->base_url}showuser={$article['article_edited_by']}'>" .
    	  $article['last_edited_by'] . "</a>" .
    	  "<br /><b>{$this->ipsclass->lang['ams_on']}:</b> {$dates['edited_date']}";
      }
    }
    
    // Set view info:
    $sec .= "<br /><br /><b>{$this->ipsclass->lang['ams_views']}:</b> {$article['article_views']}";
    
    // Add article info section:
    $this->core->menu_block_section( 'ams_article_info' , $sec );
    
    // Add it to the menu:
    $this->core->menu_add_block();
  }
	
	/**
	* @todo Check for api-needins
	*/
	function rev_view()
	{
    //----
    // Preview the specified revision without making it active or approving it
    //----
    
    $this->ipsclass->DB->simple_construct( array( 'select' => 'a.*, c.*, m.members_display_name, e.members_display_name as last_edited_by',
                                                  'from' => array( 'ams_content' => 'c'),
                                                  'add_join' => array( 1 =>
                                                                array( 'type' => 'left',
                                                                       'from' => array( 'ams_articles' => 'a'),
                                                                       'where' => 'c.content_article=a.article_id'
                                                                     ),
                                                                       2 =>
                                                                array( 'type' => 'left',
                                                                       'from' => array( 'members' => 'm' ),
                                                                       'where' => 'm.id=a.article_author'
                                                                     ),
                                                                       3 =>
                                                                array( 'type' => 'left',
                                                                       'from' => array( 'members' => 'e' ),
                                                                       'where' => 'e.id=c.content_author'
                                                                     )
                                                                     ),                                                                 
                                                  'where' => 'c.content_id = ' . $this->ipsclass->input['id']
                                                  ) );
    $article = $this->ipsclass->DB->simple_exec();
    $article = $this->ipsclass->DB->fetch_row( $article );
    
    // Check for guest-age.
    if ( !is_numeric( $article['content_author'] ) )
    {
      $article['last_edited_by'] = $article['content_author'];
      $article['content_author'] = 0;
    }
    
    $dates = array( 'created_date' => $this->ipsclass->get_date( $article['article_created_date'], '' ),
                    'edited_date' => $this->ipsclass->get_date( $article['article_edited_date'], '' ) );
    
    require_once( $this->ipsclass->vars['base_path'] . 'sources/handlers/han_parse_bbcode.php' ); 
    $parse = new parse_bbcode();
    $parse->ipsclass =& $this->ipsclass;
    $parse->parse_html = 0;
    $parse->parse_nl2br = 1;
    $body = $parse->pre_display_parse( $article['content_content'] );
    
    if ( $this->ipsclass->member['g_ams_ismod'] == '1' )
    {
      // Add a block of options on teh left. Wheeedoggy
      $this->core->menu_block( 'ams_this_rev' );
    
      // Set up the links:
      $opts = array( 'ams_mq_diff' => 'mod=article&op=diff&id='.$this->ipsclass->input['id'],
                     'ams_mq_app' => 'mod=moderator&op=mq_con_app&id='.$this->ipsclass->input['id'],
                     'ams_mq_den' => 'mod=moderator&op=mq_con_den&id='.$this->ipsclass->input['id'], );
    
      // Add 'article options' section:
      $this->core->menu_block_section( 'ams_rev_opts' , $opts );
      
      /**
      * @todo We needs to fix this... IPB-only linkage going on.
      */
      if ( $article['content_author'] == 0 )
      {
        $sec .= "<b>" . $this->ipsclass->lang['ams_rev_who'] . ":</b> <i>" . $article['last_edited_by'] . '</i>' .
        "<br /><b>{$this->ipsclass->lang['ams_on']}:</b> {$dates['edited_date']}";
      }
      else
      {
        $sec .= "<b>" . $this->ipsclass->lang['ams_rev_who'] . ":</b> " .
        "<a href='{$this->ipsclass->base_url}showuser={$article['content_author']}'>" .
        $article['last_edited_by'] . '</a>' .
        "<br /><b>{$this->ipsclass->lang['ams_on']}:</b> {$dates['edited_date']}";
      }
      
      // Add the 'article info' section:
      $this->core->menu_block_section( 'ams_rev_info' , $sec );
    
      // Add it to the menu:
      $this->core->menu_add_block();
    }
    
    $this->core->out .= $this->core->templates['mod']->revision_manager_revview($article,$dates,$body);
	}
	
	/**
	* @todo Check for api-needins
	* @todo Pass messages (deleted, not deleted, etc.)
	*/
	function rev_del()
	{
    //----
    // Remove revision from existance, forcibly...
    //----
    
	  $this->ipsclass->DB->simple_construct( array( 'select' => 'a.article_id, a.article_content, a.article_revisions, c.content_id, c.content_article',
	                                                'from' => array( 'ams_articles' => 'a' ),
	                                                'add_join' => array( 1 =>
	                                                              array( 'type' => 'left',
	                                                                     'from' => array( 'ams_content' => 'c' ),
	                                                                     'where' => 'c.content_id = ' . $this->ipsclass->input['id']
	                                                                   )
	                                                                   ),
	                                                'where' => 'a.article_id = c.content_article'
	                                              )
	                                              );
	  $this->ipsclass->DB->simple_limit( 1 );
	  $check = $this->ipsclass->DB->simple_exec();
	  $data = $this->ipsclass->DB->fetch_row($check);
	  $newcount = $data['article_revisions'] - 1;
	  
    //----
    // Placeholder: Need to add proper boinking
    //----
	  
	  if ( $data['article_content'] != $data['content_id'] )
	  {
	    $message = $this->ipsclass->lang['ams_revision_deleted'];
	    $this->ipsclass->DB->simple_delete( 'ams_content', 'content_id = ' . $this->ipsclass->input['id'] );
	    $this->ipsclass->DB->simple_exec();
	  }
	  else
	  {
	    $message = $this->ipsclass->lang['ams_rev_is_active'];
	  }
	  
	  $this->lib_global->add_log('revdel', $this->ipsclass->input['id'], $this->ipsclass->lang['ams_rev_deleted_for'].' '.$data['article_id'].'.');
	  $this->ipsclass->boink_it( $this->core->base_url . 'mod=moderator&op=rev_list&id=' . $data['article_id'] );
	}
	
	/**
	* @todo Check for api-needins
	* @todo Pass messages (restored)
	*/
	function rev_restore()
	{
    //----
    // Set the specified revision as the currently active revision
    //----
    
	  $update = array( 'article_content' => $this->ipsclass->input['cid'] );
	  $this->ipsclass->DB->do_update( 'ams_articles', $update, 'article_id = \'' . $this->ipsclass->input['id'] . '\'' );
	  
	  $this->lib_global->add_log('revrestore', $this->ipsclass->input['cid'], $this->ipsclass->lang['ams_rev_restored_for'].' '.$this->ipsclass->input['id'].'.');
	  $this->ipsclass->boink_it( $this->core->base_url . 'mod=moderator&op=rev_list&id=' . $this->ipsclass->input['id'] );
	}
	
	/**
	* @todo Check for api-needins
	*/
	function mq_list()
	{
	  //----
	  // Clean up and assign article/content revision start values
	  //----
	  $astart = ( empty($this->ipsclass->input['ast']) ) ? '0' : $this->ipsclass->input['ast'];
	  $cstart = ( empty($this->ipsclass->input['cst']) ) ? '0' : $this->ipsclass->input['cst'];

	  $this->ipsclass->DB->simple_select( '*', 'ams_articles', 'article_is_queued = \'1\'' );
	  $this->ipsclass->DB->simple_order( 'article_created_date ASC' );
	  $this->ipsclass->DB->simple_limit( $astart, $this->ipsclass->vars['ams_mq_count'] );
	  $art = $this->ipsclass->DB->simple_exec();
	  
	  $this->ipsclass->DB->simple_construct( array( 'select' => 'a.*,c.*',
	                                                'from' => array( 'ams_content' => 'c' ),
	                                                'add_join' => array( 1 =>
	                                                              array( 'type' => 'left',
	                                                                     'from' => array( 'ams_articles' => 'a' ),
	                                                                     'where' => 'a.article_id=c.content_article' )),
	                                                'where' => 'c.content_is_queued = \'1\'' ) );
	  $this->ipsclass->DB->simple_order( 'content_date ASC' );
	  $this->ipsclass->DB->simple_limit( $cstart, $this->ipsclass->vars['ams_mq_count'] );
	  $cont = $this->ipsclass->DB->simple_exec();
	  
	  $this->core->nav_add( $this->ipsclass->lang['ams_mq_link'] , 'mod=moderator&op=mq_list' );
	  
	  $article = '';
	  $content = '';
	  
    //----
    // Pull counts to accurately guage the number of pagination links needed
    //----
	  
	  $this->ipsclass->DB->simple_select( 'count(*) as cnt', 'ams_articles', 'article_is_queued = \'1\'' );
    $artcount = $this->ipsclass->DB->simple_exec();
	  $artcount = $this->ipsclass->DB->fetch_row( $artcount );
	  $artcount = $artcount['cnt'];
	  
	  $this->ipsclass->DB->simple_select( 'count(*) as cnt', 'ams_content', 'content_is_queued = \'1\'' );
    $contcount = $this->ipsclass->DB->simple_exec();
	  $contcount = $this->ipsclass->DB->fetch_row( $contcount );
	  $contcount = $contcount['cnt'];
	  
	  while ( $res = $this->ipsclass->DB->fetch_row($art) )
	  {
	  	$res['date'] = $this->ipsclass->get_date( $res['article_created_date'], '' );
	  	
	  	$article .= $this->core->templates['mod']->queue_artrow( $res );
	  }
	  
	  while ( $res = $this->ipsclass->DB->fetch_row($cont) )
	  {
	  	$res['date'] = $this->ipsclass->get_date( $res['content_date'], '' );
	  	
	  	$content .= $this->core->templates['mod']->queue_controw( $res );
	  }

		$artlinks = $this->ipsclass->build_pagelinks( array( 'TOTAL_POSS' => $artcount,
		                                                     'PER_PAGE'   => $this->ipsclass->vars['ams_mq_count'],
		                                                     'USE_ST'     => 'ast',
		                                                     'CUR_ST_VAL' => $astart,
		                                                     'BASE_URL'   => $this->core->base_url.'mod=moderator&op=mq_list&cst='
		                                                  . $cstart ) );

		$contlinks = $this->ipsclass->build_pagelinks( array( 'TOTAL_POSS' => $contcount,
		                                                  'PER_PAGE' => $this->ipsclass->vars['ams_mq_count'],
		                                                  'USE_ST' => 'cst',
		                                                  'CUR_ST_VAL' => $cstart,
		                                                  'BASE_URL'    => $this->core->base_url.'mod=moderator&op=mq_list&ast='
		                                                  . $astart ) );

	  $this->core->out .= $this->core->templates['mod']->queue_index( $article, $content, $artlinks, $contlinks );
	}
	
	/**
	* @todo Check for api-needins
	*/
	function mq_art_app()
	{
	  //----
	  // Approve queued article
	  //----
	  
	  $astart = ( empty($this->ipsclass->input['ast']) ) ? '0' : $this->ipsclass->input['ast'];
	  $cstart = ( empty($this->ipsclass->input['cst']) ) ? '0' : $this->ipsclass->input['cst'];
	  
	  $this->ipsclass->DB->do_update( 'ams_articles', array( 'article_is_queued' => '0' ), 'article_id = ' . $this->ipsclass->input['id'] );
	  
	  /**
	  * @todo Enable when watchlist is bein' done
	  */
	  // $this->core->watchlist_alert( $this->ipsclass->input['id'] , 1 );
	  
	  $this->lib_global->add_log('mqapp', $this->ipsclass->input['id'], $this->ipsclass->lang['ams_modq_approved']);
	  $this->ipsclass->boink_it( $this->core->base_url . 'mod=moderator&op=mq_list&ast=' . $astart . '&cst=' . $cstart . '' );
	}
	
	/**
	* @todo Check for api-needins
	*/
	function mq_art_den()
	{
	  //----
	  // Deny (and subsequently delete) queued article
	  //----
	  
	  $this->ipsclass->DB->simple_delete( 'ams_articles', 'article_id = ' . $this->ipsclass->input['id'] );
	  $this->ipsclass->DB->simple_exec();
	  $this->lib_global->add_log('mqdel', $this->ipsclass->input['id'], $this->ipsclass->lang['ams_modq_denied']);
	  $this->ipsclass->boink_it( $this->core->base_url . 'mod=moderator&op=mq_list' );
	}
	
	/**
	* @todo Check for api-needins
	*/
	function mq_con_app()
	{
	  //----
	  // Approve queued content revision. This also sets this revision as the article's active revision
	  //----
	  
	  $this->ipsclass->DB->simple_select( '*', 'ams_content', 'content_id = ' . $this->ipsclass->input['id'] );
	  $cont = $this->ipsclass->DB->simple_exec();
	  $cont = $this->ipsclass->DB->fetch_row($cont);
	  
	  $this->ipsclass->DB->do_update( 'ams_articles', array( 'article_content' => $this->ipsclass->input['id'],
	                                                         'article_edited_by' => $cont['content_author'],
	                                                         'article_edited_date' => $cont['content_date'] ), 'article_id = ' . $cont['content_article'] );
	  $this->ipsclass->DB->do_update( 'ams_content', array( 'content_is_queued' => '0' ), 'content_id = ' . $this->ipsclass->input['id'] );
	  
	  $this->lib_global->add_log('mq_conapp', $this->ipsclass->input['id'], $this->ipsclass->lang['ams_rev_approved_for'].': '.$cont['content_article'].'.');
	  $this->ipsclass->boink_it( $this->core->base_url . 'mod=moderator&op=mq_list' );
	}
	
	/**
	* @todo Check for api-needins
	*/
	function mq_con_den()
	{
	  //----
	  // Deny (and subsequently delete) queued content revision
	  //----
	  
	  $this->ipsclass->DB->simple_delete( 'ams_content', 'content_id = ' . $this->ipsclass->input['id'] );
	  $this->ipsclass->DB->simple_exec();
	  
	  $this->lib_global->add_log('mq_condel', $this->ipsclass->input['id'], $this->ipsclass->lang['ams_modq_deleted']);
	  $this->ipsclass->boink_it( $this->core->base_url . 'mod=moderator&op=mq_list' );
	}
}

?>